$(document).ready(function(){
	$("#txt_solicitante").autocomplete({
			source: function(request, response) {
			
				$.ajax({
					url: jQuery.scriptPath +'index.php/Persona/busquedaper/',
					dataType: "json",
					data: request,
					success: function(data) {
						response(data);
					}
				});
			},
			minLength: 2,
			select: function(event, ui) {
				//$(this).data('id', ui.item.id);
				//alert($(this).data("id"));
				$('#hd_codsoli').val(ui.item.id);
				$('#hd_codsoli').data('codsoli',ui.item.id);
				//alert(ui.item ? ("Selected: " + ui.item.value + " aka " + ui.item.id) : "Nothing selected, input was " + this.value);
			}
		});
		
		
		$("#txt_proveedor").autocomplete({
			source: function(request, response) {
			
				$.ajax({
					url: jQuery.scriptPath +'index.php/Proveedor/busquedaprovee/',
					dataType: "json",
					data: request,
					success: function(data) {
						response(data);
					}
				});
			},
			minLength: 2,
			select: function(event, ui) {
				//$(this).data('id', ui.item.id);
				//alert($(this).data("id"));
				$('#hd_codprovee').val(ui.item.id);
				$('#hd_codprovee').data('codprovee',ui.item.id);
				//alert(ui.item ? ("Selected: " + ui.item.value + " aka " + ui.item.id) : "Nothing selected, input was " + this.value);
			}
		});
});
function callbackbusmatprima(){
		$(".busmantprima").autocomplete({
			source: function(request, response) {
			
				$.ajax({
					url: jQuery.scriptPath +'index.php/MateriaPrima/busquedajson/',
					dataType: "json",
					data: request,
					success: function(data) {
						response(data);
					}
				});
			},
			minLength: 2,
			select: function(event, ui) {
				cell= $(this).parent();
				q=ui.item.id;
                 $('#cod_mateprima', cell).val(q);
					$.get(jQuery.scriptPath +'index.php/Llenarcombos/combocombinahtml/?term='+q, function(data) {
						$('#cod_combin', cell.parent()).html(data);
					});
			}
		});
	$('.actionbuscar').click(function(){
		$obj = $(this).parent().parent();
		VentanaPopUp(300,300,true,"Seleccionar...",'Almacen/selectalmacen',//?attrID='+$(this).val()
						{
							Aceptar: function(){
								q=$('#cbocod_division').val();
								textalma = $('#cbocod_almacen option:selected').text();
								textsec = $('#cbocod_sector option:selected').text();
								textlugar = $('#cbocod_lugaralma option:selected').text();
								textdivi = $('#cbocod_division option:selected').text();
								
								$('#cod_div', $obj).val(q);
								$('#txt_lugaralmacen', $obj).val(textalma+' - '+textsec+' - '+textlugar+' - '+textdivi);
																	
								$( this ).dialog( "close" );
								$('#cant', $obj).focus();
							},
							Cancel: function() {
								$( this ).dialog( "close" );
							}
						}
					,true,999);
		
		
	});
}
function ExecActionMante(type){
	cod_present 	= $('#hdcod_present').val();
	ds_descrip 	= $('#txtds_descrip').val();
	ds_abr 	= $('#txtds_abr').val();
	st_stado	= '1';
	
	$.ajax({
 		dataType: "html",
	 	type: "POST",
	 	url: jQuery.scriptPath +'index.php/Lugaralmc/executemante/',
	 	data: "type="+type+"&cod_present="+cod_present+"&ds_descrip="+ds_descrip
	 			+"&ds_abr="+ds_abr+'&st_stado='+st_stado,
		beforeSend: function(data){

		},
		success: function(requestData){
			//alert(requestData); 	
			$("#result").html(requestData);
		},		
		error: function(requestData, strError, strTipoError){											
			$("#result").html("Error " + strTipoError +": " + strError);
			//alert("Error " + strTipoError +": " + strError);
		}
	});
}
LlenarCombosector = function(b){
	
		$.ajax({
 		dataType: "html",
	 	type: "POST",
	 	url: jQuery.scriptPath +'index.php/Llenarcombos/combosector/',
	 	data: "cod_almacen="+$(b).val(),
		beforeSend: function(data){

		},
		success: function(requestData){
			$("body").append(requestData);
		},		
		error: function(requestData, strError, strTipoError){											
			alert("Error " + strTipoError +": " + strError);
		}
	});
}